//Page Object
const url = require('../../config/config.js')
Page({
    data: {
        customer: {},
        // id用来判断是哪个用户的id

    },
    onShow() {
        const token = wx.getStorageSync("token");
        console.log(token)
        if (!token) {
            wx.navigateTo({
                url: '/pages/login/index'
            });
        }

    },
    //options(Object)
    onLoad: function(options) {
        const { id } = options;
        this.getCustomerDetail(id)
    },
    getCustomerDetail(id) {
        const header = {
            'content-type': 'application/json',
            'Cookie': "JSESSIONID=" + wx.getStorageSync("token") //读取cookie
        }
        wx.request({
            url: url.b.getUserById,
            data: { id },
            header: header,
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            success: (result) => {
                try {
                    const { id } = result.data.data.data;
                    console.log(id)
                    wx.setStorageSync("customerID", id);
                    this.setData({
                        customer: result.data.data.data
                    })
                } catch (error) {
                    wx.showToast({
                        title: '登陆过期',
                        icon: 'none',
                    });
                    wx.removeStorageSync({ token: "token" });
                    wx.navigateTo({
                        url: '/pages/login/index',

                    });

                }


            },
            fail: () => {},
            complete: () => {}
        });

    }

});